{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37864bit9859aadc2f9b4163a401bc1d107b5e60",
   "display_name": "Python 3.7.8 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "We are the knights who say \"Ni！\"\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "基本方法\n",
    "'''\n",
    "print('We are the {} who say \"{}！\"'.format('knights', 'Ni'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "spam and eggs\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "花括号中格式字段可以用 数字索引指定位置\n",
    "'''\n",
    "arg_tuple = ('spam', 'eggs')\n",
    "print('{0} and {1}'.format('spam', 'eggs'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "eggs and spam\n"
     ]
    }
   ],
   "source": [
    "print('{1} and {0}'.format('spam', 'eggs'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "This spam is absolutely horrible.\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "花括号中使用关键字参数，可使用参数的名称引用他们的值\n",
    "'''\n",
    "print('This {food} is {adjective}.'.format(\n",
    "    food='spam', adjective= 'absolutely horrible'\n",
    "))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Jack: 4098; Sjoerd: 4127; Dcab: 8637678\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "使用简单的传递字典并使用[]访问键来完成\n",
    "'''\n",
    "table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}\n",
    "print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; Dcab: {0[Dcab]:d}'.format(table))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Jackylove: 12000 - Knight: 24000 - Karsa: 36000\n"
     ]
    }
   ],
   "source": [
    "table = {'Jackylove': 12000, 'Knight': 24000, 'Karsa': 36000}\n",
    "print('Jackylove: {Jackylove:d} - Knight: {Knight:d} - Karsa: {Karsa:d}'.format(**table))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      " 1 -   1 -    1\n 2 -   4 -    8\n 3 -   9 -   27\n 4 -  16 -   64\n 5 -  25 -  125\n 6 -  36 -  216\n 7 -  49 -  343\n 8 -  64 -  512\n 9 -  81 -  729\n10 - 100 - 1000\n"
     ]
    }
   ],
   "source": [
    "for x in range(1, 11):\n",
    "    print('{0:2d} - {1:3d} - {2:4d}'.format(x, x*x, x*x*x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "11 22 33\n"
     ]
    }
   ],
   "source": [
    "lst = ['11', '22', '33']\n",
    "print('{0} {1} {2}'.format(*lst))"
   ]
  }
 ]
}